package br.unipar.bancodedados.command;

import br.unipar.bancodedados.manager.ConnectionSingleton;
import java.sql.SQLException;
import java.sql.Statement;

public class CommandInvoker {

    public void invoke(Command command) {
        try {
            Statement stmt = ConnectionSingleton.getInstance().createStatement();
            try {
                stmt.execute("begin");

                command.execute(stmt);

                stmt.execute("commit");
            } catch (Exception e) {
                stmt.execute("rollback");
            }

            stmt.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}
